/*
 * @Author: xiehangyun 
 * @Date: 2025-05-10 18:19:41 
 * @Last Modified by: 肖思汗
 * @Last Modified time: 2025-06-10 20:43:02
 */

import { View, Text } from '@tarojs/components';
import Taro, { useRouter } from "@tarojs/taro";
import { ReactNode } from "react";
import CustomHeader from 'src/components/CustomHeader/CustomHeader';
import styles from "./orderComplete.module.less";
import { Button } from '@nutui/nutui-react-taro';

interface OrderCompleteProps {
  children?: ReactNode
}

//订单支付完成页面
export default function OrderComplete(props: OrderCompleteProps) {
  const router = useRouter();
  const orderId = router.params.orderId || '123456789';
  const paymentMethod = router.params.paymentMethod || 'wechat';
  
  const getPaymentMethodName = () => {
    switch(paymentMethod) {
      case 'wechat': return '微信支付';
      case 'alipay': return '支付宝';
      case 'bank': return '银行卡支付';
      default: return '支付';
    }
  };
  const estimatedDelivery = new Date(Date.now() + 3 * 24 * 60 * 60 * 1000).toLocaleDateString();

  const handleBackHome = () => {
    Taro.switchTab({
      url: '/pages/Home/Home'
    });
  };

  const handleViewOrder = () => {
    Taro.navigateTo({
      url: `/pages/OrderDetail/OrderDetail?orderId=${orderId}`
    });
  };

  return (
    <View className={styles.orderComplete}>
      <CustomHeader showBack={true} />
      
      <View className={styles.content}>
        <View className={styles.successIcon}>
          {/* <Icon name="check" size="40" color="#07C160" /> */}
        </View>
        <Text className={styles.title}>订单支付成功</Text>
        <Text className={styles.orderNumber}>订单号: {orderId}</Text>
        <Text className={styles.paymentMethod}>支付方式: {getPaymentMethodName()}</Text>
        
        <View className={styles.deliveryInfo}>
          <Text className={styles.deliveryText}>预计送达时间</Text>
          <Text className={styles.deliveryDate}>{estimatedDelivery}</Text>
        </View>

        <View className={styles.buttonGroup}>
          <Button 
            type="default" 
            className={styles.button}
            onClick={handleBackHome}
          >
            返回首页
          </Button>
          <Button 
            type="primary" 
            className={styles.button}
            onClick={handleViewOrder}
          >
            查看订单
          </Button>
        </View>
      </View>
    </View>
  );
}